package com.ruoyi.project.product.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.product.domain.InsReagentBottleBac;
import com.ruoyi.project.product.service.IInsReagentBottleBacService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 试剂瓶记录Controller
 *
 * @author taney
 * @date 2020-12-30
 */
@AllArgsConstructor
@RestController
@RequestMapping("/product/reagentBottleBac" )
public class InsReagentBottleBacController extends BaseController {

    private final IInsReagentBottleBacService iInsReagentBottleBacService;

    /**
     * 查询试剂瓶记录列表
     */
    @PreAuthorize("@ss.hasPermi('product:reagentBottleBac:list')")
    @GetMapping("/list")
    public TableDataInfo list(InsReagentBottleBac insReagentBottleBac)
    {
        startPage();
        LambdaQueryWrapper<InsReagentBottleBac> lqw = new LambdaQueryWrapper<InsReagentBottleBac>();
        if (insReagentBottleBac.getBoxId() != null){
            lqw.eq(InsReagentBottleBac::getBoxId ,insReagentBottleBac.getBoxId());
        }
        if (insReagentBottleBac.getOrderListId() != null){
            lqw.eq(InsReagentBottleBac::getOrderListId ,insReagentBottleBac.getOrderListId());
        }
        if (insReagentBottleBac.getOrderId() != null){
            lqw.eq(InsReagentBottleBac::getOrderId ,insReagentBottleBac.getOrderId());
        }
        if (StringUtils.isNotBlank(insReagentBottleBac.getMachineType())){
            lqw.eq(InsReagentBottleBac::getMachineType ,insReagentBottleBac.getMachineType());
        }
        if (StringUtils.isNotBlank(insReagentBottleBac.getProjectCode())){
            lqw.eq(InsReagentBottleBac::getProjectCode ,insReagentBottleBac.getProjectCode());
        }
        if (StringUtils.isNotBlank(insReagentBottleBac.getProjectName())){
            lqw.like(InsReagentBottleBac::getProjectName ,insReagentBottleBac.getProjectName());
        }
        if (StringUtils.isNotBlank(insReagentBottleBac.getTestMethod())){
            lqw.eq(InsReagentBottleBac::getTestMethod ,insReagentBottleBac.getTestMethod());
        }
        if (StringUtils.isNotBlank(insReagentBottleBac.getReagentType())){
            lqw.eq(InsReagentBottleBac::getReagentType ,insReagentBottleBac.getReagentType());
        }
        if (StringUtils.isNotBlank(insReagentBottleBac.getExpireDate())){
            lqw.eq(InsReagentBottleBac::getExpireDate ,insReagentBottleBac.getExpireDate());
        }
        if (StringUtils.isNotBlank(insReagentBottleBac.getLotNo())){
            lqw.eq(InsReagentBottleBac::getLotNo ,insReagentBottleBac.getLotNo());
        }
        if (StringUtils.isNotBlank(insReagentBottleBac.getBarcode())){
            lqw.eq(InsReagentBottleBac::getBarcode ,insReagentBottleBac.getBarcode());
        }
        if (StringUtils.isNotBlank(insReagentBottleBac.getPrintState())){
            lqw.eq(InsReagentBottleBac::getPrintState ,insReagentBottleBac.getPrintState());
        }
        if (StringUtils.isNotBlank(insReagentBottleBac.getBarcodeOriginal())){
            lqw.eq(InsReagentBottleBac::getBarcodeOriginal ,insReagentBottleBac.getBarcodeOriginal());
        }
        List<InsReagentBottleBac> list = iInsReagentBottleBacService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出试剂瓶记录列表
     */
    @PreAuthorize("@ss.hasPermi('product:reagentBottleBac:export')" )
    @Log(title = "试剂瓶记录" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(InsReagentBottleBac insReagentBottleBac) {
        LambdaQueryWrapper<InsReagentBottleBac> lqw = new LambdaQueryWrapper<InsReagentBottleBac>(insReagentBottleBac);
        List<InsReagentBottleBac> list = iInsReagentBottleBacService.list(lqw);
        ExcelUtil<InsReagentBottleBac> util = new ExcelUtil<InsReagentBottleBac>(InsReagentBottleBac. class);
        return util.exportExcel(list, "reagentBottleBac" );
    }

    /**
     * 获取试剂瓶记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:reagentBottleBac:query')" )
    @GetMapping(value = "/{bottleId}" )
    public AjaxResult getInfo(@PathVariable("bottleId" ) Integer bottleId) {
        return AjaxResult.success(iInsReagentBottleBacService.getById(bottleId));
    }

    /**
     * 新增试剂瓶记录
     */
    @PreAuthorize("@ss.hasPermi('product:reagentBottleBac:add')" )
    @Log(title = "试剂瓶记录" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InsReagentBottleBac insReagentBottleBac) {
        return toAjax(iInsReagentBottleBacService.save(insReagentBottleBac) ? 1 : 0);
    }

    /**
     * 修改试剂瓶记录
     */
    @PreAuthorize("@ss.hasPermi('product:reagentBottleBac:edit')" )
    @Log(title = "试剂瓶记录" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InsReagentBottleBac insReagentBottleBac) {
        return toAjax(iInsReagentBottleBacService.updateById(insReagentBottleBac) ? 1 : 0);
    }

    /**
     * 删除试剂瓶记录
     */
    @PreAuthorize("@ss.hasPermi('product:reagentBottleBac:remove')" )
    @Log(title = "试剂瓶记录" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{bottleIds}" )
    public AjaxResult remove(@PathVariable Integer[] bottleIds) {
        return toAjax(iInsReagentBottleBacService.removeByIds(Arrays.asList(bottleIds)) ? 1 : 0);
    }
}